<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require_once 'includes/connect.php';
require_once 'includes/function.php';
//$pet_id = $_REQUEST["pet_id"];
$return_id = $_REQUEST["return_id"];
$promise_id = $_REQUEST["promise_id"];
$borrow_id = $_REQUEST["borrow_id"];

$return_amount = $_REQUEST["return_amount"];
$task = $_REQUEST["task"];

$db = new myDBS();

switch ($task) {
    case "cancel":
        $sql = "UPDATE tbl_promise_budget SET remain = remain + $return_amount "
                . " WHERE id = '$promise_id'";
        
        $db->runSQL($sql) or die(mysql_error());
        
        $sql = "UPDATE tbl_return "
                . " SET status = 'cancel'"
                . " WHERE return_id = '$return_id'";
        $db->runSQL($sql) or die(mysql_error());
        //echo $sql;
        break;
    
    case "return_borrow_cancel":
        $sql = "UPDATE tbl_promise_borrow SET remain = remain + $return_amount "
                . " WHERE borrow_id = '$borrow_id'";
        
        $db->runSQL($sql) or die(mysql_error());
        
        $sql = "UPDATE tbl_return "
                . " SET status = 'cancel'"
                . " WHERE return_id = '$return_id'";
        $db->runSQL($sql) or die(mysql_error());
        break;
}
?>

